package com.cicigodd.brick.plug.system.dict.controller;

import com.cicigodd.brick.plug.annotation.repeatsubmit.RepeatSubmit;
import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.system.dict.request.*;
import com.cicigodd.brick.plug.system.dict.response.SysDictValueDetailResponse;
import com.cicigodd.brick.plug.system.dict.response.SysDictValueListResponse;
import com.cicigodd.brick.plug.system.dict.service.SysDictValueService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;


@Api(tags = "系统字典")
@RestController
public class SysDictValueController {

    @Resource
    private SysDictValueService sysDictValueService;

    @RepeatSubmit
    @ApiOperation(value = "系统字典添加", notes = "系统字典添加")
    @PostResource(name = "系统字典添加", path = "/sysDictValue/add")
    public Result add(@RequestBody @Validated SysDictValueAddRequest sysDictValueAddRequest) {
        sysDictValueService.add(sysDictValueAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典删除", notes = "根据id删除")
    @DeleteResource(name = "系统字典删除", path = "/sysDictValue/delete")
    public Result delete(@Validated SysDictValueDeleteRequest sysDictValueDeleteRequest) {
        sysDictValueService.delete(sysDictValueDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典编辑", notes = "系统字典编辑")
    @PutResource(name = "系统字典编辑", path = "/sysDictValue/edit")
    public Result edit(@RequestBody @Validated SysDictValueEditRequest sysDictValueEditRequest) {
        sysDictValueService.edit(sysDictValueEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典详情", notes = "根据id查询")
    @GetResource(name = "系统字典详情", path = "/sysDictValue/detail")
    public Result<SysDictValueDetailResponse> detail(SysDictValueDetailRequest sysDictValueDetailRequest) {
        SysDictValueDetailResponse detail = sysDictValueService.detail(sysDictValueDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "系统字典分页列表", notes = "系统字典分页列表")
    @GetResource(name = "系统字典分页列表", path = "/sysDictValue/list")
    public Result<PageResult<SysDictValueListResponse>> list(SysDictValueListRequest sysDictValueListRequest) {
        PageResult<SysDictValueListResponse> pageList =  sysDictValueService.list(sysDictValueListRequest);
        return ResultGenerator.successResult(pageList);
    }

    @ApiOperation(value = "根据字典类型查询", notes = "根据字典类型查询")
    @GetResource(name = "根据字典类型查询", path = "/sysDictValue/detailByType")
    public Result<List<SysDictValueDetailResponse>> detailByType(SysDictValueDetailByTypeRequest sysDictValueDetailByTypeRequest) {
        List<SysDictValueDetailResponse> list = sysDictValueService.detailByType(sysDictValueDetailByTypeRequest.getDictType());
        return ResultGenerator.successResult(list);
    }

    @ApiOperation(value = "根据字典类型和编码查询", notes = "根据字典类型和编码查询")
    @GetResource(name = "根据字典类型和编码查询", path = "/sysDictValue/detailByTypeAndCode")
    public Result<SysDictValueDetailResponse> detailByTypeAndCode(SysDictValueDetailByTypeAndCodeRequest sysDictValueDetailByTypeAndCodeRequest) {
        SysDictValueDetailResponse detail = sysDictValueService.detailByTypeAndCode(sysDictValueDetailByTypeAndCodeRequest.getDictType(),sysDictValueDetailByTypeAndCodeRequest.getDictCode());
        return ResultGenerator.successResult(detail);
    }
}
